package com.example.netty_pipline.pipeline.handler;

import com.example.netty_pipline.pipeline.ChannelHandlerContext;
import com.example.netty_pipline.pipeline.ChannelInboundHandler;

/**
 * 字符串解码器 - 将字节数组转换为字符串
 */
public class StringDecoder implements ChannelInboundHandler {
    
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        if (msg instanceof byte[]) {
            String decoded = new String((byte[]) msg);
            System.out.println("[StringDecoder] Decoded: " + decoded);
            ctx.fireChannelRead(decoded);
        } else {
            ctx.fireChannelRead(msg);
        }
    }
}